package com.example.base;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;

/*
 * 基于TCP协议的Socket通信，实现远程关机
 * 接收方
 */
public class Receiver {
    public static void main(String[] args) {
        try {
            ServerSocket serverSocket = new ServerSocket(8888);
            System.out.println("等待接收信息");
            Socket socket = serverSocket.accept();
            Scanner input = new Scanner(socket.getInputStream());
            if (input.hasNext() && input.nextLine().equals("shutdown")){
                Shutdown.shutdown();
            }
            socket.shutdownInput();
            input.close();
            socket.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}